<template>
  <div>
    <div class="head-container">
      <el-input
        v-model="deptName"
        placeholder="请输入部门名称"
        clearable
        size="small"
        prefix-icon="el-icon-search"
        style="margin-bottom: 20px"
      />
    </div>
    <div
      class="head-container"
      ref="scrollContainer"
    >
      <el-tree
        :data="deptOptions"
        :props="defaultProps"
        :expand-on-click-node="false"
        :filter-node-method="filterNode"
        ref="tree"
        node-key="id"
        default-expand-all
        highlight-current
        @node-click="handleNodeClick"
      />
    </div>
  </div>
</template>

<script>
import treeData from './treeData.js'

export default {
  data () {
    return {
      deptOptions: treeData,
      defaultProps: {
        children: 'children',
        label: 'label'
      },
      deptName: ''
    }
  },
  methods: {
    // 筛选节点
    filterNode (value, data) {
      if (!value) return true
      return data.label.indexOf(value) !== -1
    },
    // 树节点点击
    handleNodeClick (data) {
      // if (!data.leaf) {
      //   this.$message.warning('当前节点不是设备')
      //   return
      // }
      // this.queryParams.deptId = data.id;
      // this.handleQuery();
      console.log(data)
      this.floc = data.floc
    }
  },
  watch: {
    // 根据名称筛选部门树
    deptName (val) {
      this.$refs.tree.filter(val)
    }
  }
}
</script>

<style>
</style>
